﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PasswordGenerator1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                string symbols = @"!?@#$%&+-*=()[]{},.:;";
                string numbers = "0123456789";
                string symbolsAndchars = chars;

                if (this.checkBoxNumbers.Checked == true)
                    symbolsAndchars = symbolsAndchars + numbers;

                if (this.checkBoxSymbols.Checked == true)
                    symbolsAndchars = symbolsAndchars + symbols;

                int passwordLength = Convert.ToInt32(textBox2.Text);
                string password = "";
                int seed = Convert.ToInt32(Math.Sqrt(DateTime.Now.Ticks));
                Random r = new Random();

                for (int i = 0; i < passwordLength; i++)
                {
                    int j = r.Next(0, symbolsAndchars.Length);
                    string letter = symbolsAndchars[j].ToString();
                    password = password + letter;
                }

                textBox1.Text = password;
            }
            catch (Exception){}
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(textBox1.Text); 
        }
    }
}
